/**
 * 
 */
package com.soft.cake.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.soft.cake.mapper.OrderProductMapper;
import com.soft.cake.pojo.Order;
import com.soft.cake.pojo.OrderProduct;
import com.soft.cake.service.IOrderProductService;

/**
 * @author CanLig
 * @date 2019年8月23日 下午1:34:25
 * @version 1.0.0
 * @description 
 * @TODO
 */
@Service
public class OrderProductServiceImpl implements IOrderProductService {

	@Autowired
	private OrderProductMapper orderProductMapper;
	
	@Override
	public List<OrderProduct> display() {
		// TODO Auto-generated method stub
		return orderProductMapper.selectByOrderId(1);
	}
	
	@Override
	public List<Integer> getProductIds(List<Order> orders) {
		List<Integer> productIds = new ArrayList<Integer>();
		for(Order order : orders) {
			int id = orderProductMapper.selectProductIdByOrderId(order.getOrderId());
			productIds.add(id);
		}
		return productIds;
	}
	
	/**
	 * @author Qijuan Liu
	 * @description 获取op的所有详情
	 * @param List<Order>
	 * @return List<OrderProduct>
	 */
	public List<OrderProduct> listAllOrderProductsByOrders(List<Order> orders){
		List<OrderProduct> orderProducts = new ArrayList<OrderProduct>();;
		for(Order order : orders) {
			OrderProduct orderProduct = orderProductMapper.selectAllOrderAndProductsByOrderId(order.getOrderId());
			orderProducts.add(orderProduct);
		}
		return orderProducts;
	}

	
	@Override
	public Integer getProductQuantityInOrder(Integer orderId, Integer productId) {
		// TODO Auto-generated method stub
		return orderProductMapper.selQuantityByOrderIdAndProductId(orderId, productId);
	}

}
